package com.insurance.controller;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.pojo.Driver;
import com.insurance.service.DriverService;
import com.insurance.utils.ConversionDateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: yjc
 * Date: 2020/10/27 17:00
 * Description:
 * Version: V1.0
 */
@Api(value = "司机端",tags = "司机端API")
@Controller
public class DriverController {
    @Autowired
    private ResultData resultData;

    @Autowired(required = false)
    private DriverService driverService;

    @ResponseBody
    @GetMapping(value = "/queryDriverById.do",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询司机个人信息",notes = "根据ID查询司机个人信息接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="查无此人")
    })
    public ResultData queryDriverById(Driver driver){
        System.out.println("打印结果："+driver);
        List<Map> mapList = driverService.queryDriverById(driver);
        if (mapList.size() > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
            resultData.setData(mapList);
            return resultData;
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无此人");
            return resultData;
        }
    }

    @ResponseBody
    @GetMapping(value = "/queryDriverOrder.do",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查看司机订单",notes = "查看司机订单接口",httpMethod = "get",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=500,message="没有订单")
    })
    public ResultData queryDriverOrder(Driver driver){
        System.out.println("打印结果："+driver);
        List<Map> mapList = driverService.queryDriverOrder(driver);
        if (mapList.size() > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
            resultData.setData(mapList);
            return resultData;
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("没有订单");
            return resultData;
        }
    }

    @ResponseBody
    @PostMapping(value = "/updateDriverOrderStatus.do",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "修改订单状态",notes = "修改订单状态接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=500,message="后台出错")
    })
    public ResultData updateDriverOrderStatus(@RequestBody Driver driver){
        System.out.println("打印结果："+driver);
        int result = driverService.updateDriverOrderStatus(driver);
        if (result > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("修改成功");
            return resultData;
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("后台出错");
            return resultData;
        }
    }

    @ResponseBody
    @PostMapping(value = "/updateDriverOrderPicktime.do",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "修改预计到达时间",notes = "修改预计到达时间接口",httpMethod = "post",response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=500,message="后台出错")
    })
    public ResultData updateDriverOrderPicktime(@RequestBody Driver driver){
        System.out.println("打印结果："+driver);
        try{
            driver.setExpectfinishTime2(ConversionDateUtils.conversionDateUtils(driver.getExpectfinishTime()));//将初登日期转换为时间戳
        }catch (Exception e){
            e.printStackTrace();
        }
        int result = driverService.updateDriverOrderPicktime(driver);
        if (result > 0){
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("修改成功");
            resultData.setData(driver);
            return resultData;
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("后台出错");
            return resultData;
        }
    }

//    @ResponseBody
//    @GetMapping(value = "/queryByProvinceDriver.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "根据省查询",notes = "根据省查询接口",httpMethod = "get",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="查询成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData queryByProvinceDriver(Driver driver){
////        int result = userServcie.queryByProvinceDriver(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("查询成功");
//            resultData.setData("省级信息");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @GetMapping(value = "/queryByCityDriver.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "查询已开通市",notes = "查询已开通市接口",httpMethod = "get",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="查询成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData queryByCityDriver(Driver driver){
////        int result = userServcie.queryByCityDriver(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("查询成功");
//            resultData.setData("市级信息");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @GetMapping(value = "/queryByAreaDriver.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "通过市id查询区域",notes = "通过市id查询区域接口",httpMethod = "get",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="查询成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData queryByAreaDriver(Driver driver){
////        int result = userServcie.queryByAreaDriver(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("查询成功");
//            resultData.setData("市级信息");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @PostMapping(value = "/downDriver.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "导出司机信息",notes = "导出司机信息接口",httpMethod = "post",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="导出成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData downDriver(Driver driver){
////        int result = userServcie.downDriver(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("导出成功");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @GetMapping(value = "/queryOrder.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "查看订单",notes = "查看订单接口",httpMethod = "get",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="查询成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData queryOrder(Driver driver){
////        int result = userServcie.queryOrder(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("查询成功");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @PostMapping(value = "/updateDriverStatus.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "修改司机状态",notes = "修改司机状态接口",httpMethod = "post",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="修改成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData updateDriverStatus(@RequestBody Driver driver){
////        int result = userServcie.updateDriverStatus(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("修改成功");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @GetMapping(value = "/queryMessageByUserId.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "查看消息",notes = "查看消息接口",httpMethod = "get",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="查询成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData queryMessageByUserId(@RequestBody Driver driver){
////        int result = userServcie.queryMessageByUserId(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("查询成功");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
//
//    @ResponseBody
//    @PostMapping(value = "/updateDriverPwd.do",produces = "application/json;charset=utf-8")
//    @ApiOperation(value = "修改司机登录密码",notes = "修改司机登录密码接口",httpMethod = "post",response = ResultData.class)
//    @ApiResponses({
//            @ApiResponse(code=200,message="修改成功"),
//            @ApiResponse(code=500,message="后台服务错误")
//    })
//    public ResultData updateDriverPwd(@RequestBody Driver driver){
////        int result = userServcie.updateDriverPwd(driver);
//        int result = 1;
//        if (result > 0){
//            resultData.setCode(Contants.SUCCESS);
//            resultData.setMsg("修改成功");
//            return resultData;
//        }else {
//            resultData.setCode(Contants.FAILURE);
//            resultData.setMsg("后台服务错误");
//            return resultData;
//        }
//    }
}
